package Singleton;


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JOptionPane;



/**
 *
 * @author diegoamt
 */
public class VentanaCajero extends JFrame implements ActionListener{
    
    
    FachadaCajero fachada = new FachadaCajero();
    
    
    /**
     * Creates new form VentanaCajero
     */
    public VentanaCajero() {
        super("Ventana Cajero");
        initComponents();
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        inicializarEventos();
    }
    
    void inicializarEventos(){
        botonRegistrarCliente.addActionListener(this);
        botonConsultarCliente.addActionListener(this);
        botonEliminarCliente.addActionListener(this);
        botonModificarCliente.addActionListener(this);
        botonRegistrarVenta.addActionListener(this);
        botonRealizarPago.addActionListener(this);
        botonGenerarFactura.addActionListener(this);
        botonSalir.addActionListener(this);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelPrincipal = new javax.swing.JPanel();
        etCajero = new javax.swing.JLabel();
        botonSalir = new javax.swing.JButton();
        panelCliente = new javax.swing.JPanel();
        botonRegistrarCliente = new javax.swing.JButton();
        botonModificarCliente = new javax.swing.JButton();
        botonEliminarCliente = new javax.swing.JButton();
        botonConsultarCliente = new javax.swing.JButton();
        panelVentas = new javax.swing.JPanel();
        botonGenerarFactura = new javax.swing.JButton();
        botonRegistrarVenta = new javax.swing.JButton();
        botonRealizarPago = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        etCajero.setFont(new java.awt.Font("Ubuntu", 1, 18)); // NOI18N
        etCajero.setText("CAJERO");

        botonSalir.setText("Salir");

        panelCliente.setBorder(javax.swing.BorderFactory.createTitledBorder("Administracion de Clientes"));

        botonRegistrarCliente.setText("Registrar Cliente");

        botonModificarCliente.setText("Modificar Cliente");

        botonEliminarCliente.setText("Eliminar Cliente");

        botonConsultarCliente.setText("Consultar Cliente");

        javax.swing.GroupLayout panelClienteLayout = new javax.swing.GroupLayout(panelCliente);
        panelCliente.setLayout(panelClienteLayout);
        panelClienteLayout.setHorizontalGroup(
            panelClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelClienteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(botonModificarCliente, javax.swing.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE)
                    .addComponent(botonRegistrarCliente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(panelClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(botonConsultarCliente, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE)
                    .addComponent(botonEliminarCliente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        panelClienteLayout.setVerticalGroup(
            panelClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelClienteLayout.createSequentialGroup()
                .addContainerGap(24, Short.MAX_VALUE)
                .addGroup(panelClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonRegistrarCliente)
                    .addComponent(botonConsultarCliente))
                .addGap(18, 18, 18)
                .addGroup(panelClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonModificarCliente)
                    .addComponent(botonEliminarCliente))
                .addGap(23, 23, 23))
        );

        panelVentas.setBorder(javax.swing.BorderFactory.createTitledBorder("Ventas"));

        botonGenerarFactura.setText("Generar Factura");

        botonRegistrarVenta.setText("Registrar Venta");

        botonRealizarPago.setText("Realizar Pago");

        javax.swing.GroupLayout panelVentasLayout = new javax.swing.GroupLayout(panelVentas);
        panelVentas.setLayout(panelVentasLayout);
        panelVentasLayout.setHorizontalGroup(
            panelVentasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelVentasLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelVentasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelVentasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(botonRealizarPago, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(botonRegistrarVenta, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE))
                    .addComponent(botonGenerarFactura, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(120, Short.MAX_VALUE))
        );
        panelVentasLayout.setVerticalGroup(
            panelVentasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelVentasLayout.createSequentialGroup()
                .addContainerGap(13, Short.MAX_VALUE)
                .addComponent(botonRegistrarVenta)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botonRealizarPago)
                .addGap(7, 7, 7)
                .addComponent(botonGenerarFactura))
        );

        javax.swing.GroupLayout panelPrincipalLayout = new javax.swing.GroupLayout(panelPrincipal);
        panelPrincipal.setLayout(panelPrincipalLayout);
        panelPrincipalLayout.setHorizontalGroup(
            panelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelPrincipalLayout.createSequentialGroup()
                .addGroup(panelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(panelPrincipalLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(panelCliente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(panelPrincipalLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(botonSalir))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelPrincipalLayout.createSequentialGroup()
                        .addGroup(panelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panelPrincipalLayout.createSequentialGroup()
                                .addGap(158, 158, 158)
                                .addComponent(etCajero))
                            .addGroup(panelPrincipalLayout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(panelVentas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 8, Short.MAX_VALUE)))
                .addContainerGap())
        );
        panelPrincipalLayout.setVerticalGroup(
            panelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPrincipalLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(etCajero)
                .addGap(18, 18, 18)
                .addComponent(panelCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(panelVentas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(botonSalir)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(panelPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        VentanaCajero v = new VentanaCajero();
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonConsultarCliente;
    private javax.swing.JButton botonEliminarCliente;
    private javax.swing.JButton botonGenerarFactura;
    private javax.swing.JButton botonModificarCliente;
    private javax.swing.JButton botonRealizarPago;
    private javax.swing.JButton botonRegistrarCliente;
    private javax.swing.JButton botonRegistrarVenta;
    private javax.swing.JButton botonSalir;
    private javax.swing.JLabel etCajero;
    private javax.swing.JPanel panelCliente;
    private javax.swing.JPanel panelPrincipal;
    private javax.swing.JPanel panelVentas;
    // End of variables declaration//GEN-END:variables

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==botonRegistrarCliente){
            fachada.registrarCliente();
        }
        if(e.getSource()==botonConsultarCliente){
            fachada.consultarCliente();
        }
        if(e.getSource()==botonEliminarCliente){
            fachada.eliminarCliente();
        }
        if(e.getSource()==botonModificarCliente){
            fachada.modificarCliente();
        }
        if(e.getSource()==botonRegistrarVenta){
            fachada.registrarVenta();
        }
        if(e.getSource()==botonRealizarPago){
            int op = Integer.parseInt(JOptionPane.showInputDialog("Digite 1 para pago fraccionado, o 2 para pago por totalidad"));
            if(op==1){
                fachada.registrarPagoFraccionado();
            }else{
                fachada.registrarPagoTotalidad();
            }
        }
        if(e.getSource()==botonGenerarFactura){
            fachada.generarFactura();
        }
        
        if(e.getSource()==botonSalir){
            System.exit(0);
        }
    }
}
